package com.glacier.common.core.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * date 2022-11-11 10:29
 * 分页实体
 *
 * @author glacier
 * @version 1.0
 */
public class Page<T extends Serializable> implements Serializable {

    private static final long serialVersionUID = 6704135231455902378L;
    /**
     * 页码
     */
    private int page;
    /**
     * 分页大小
     */
    private int limit;
    /**
     * 总数
     */
    private long total;
    /**
     * 数据
     */
    private List<T> data;

    public Page() {
        page = 0;
        limit = 10;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public List<T> getData() {
        return Optional.ofNullable(data)
                .orElseGet(() -> data = new ArrayList<>(1));
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Page{" +
                "page=" + page +
                ", limit=" + limit +
                ", total=" + total +
                ", data=" + data +
                '}';
    }
}
